<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
    <%@include file="/resources/datepicker/datepicker.jsp"%> 
    <title> </title>
    <script type="text/javascript">
        var datagrid;
        var message =$.messager;
        var operateDialog;
        $(function() {
            datagrid=$('#datagrid').datagrid({
                url : '${path}/business/ipic_system/incoming/ajaxList.do',
                 onLoadSuccess:function(){
                }
            });
        });
        //子页面返回方法
        function returnResult(){
            operateDialog.dialog('close');
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('reload');
        }
        //判断选择单据是否是一条
        function isChooseOne(rows){
            var flag = false;
            if(rows.length >1 ) {
                message.show({
                    msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            } else if (rows.length == 0) {
                message.show({
                    msg : "<spring:message code='msg.please.choose'/>",
                    title : '<spring:message code='msg.tip'/>'
                });
                flag = false;
            }else{
                flag = true;
            }
            return flag;
        }
        function search_() {
            datagrid.datagrid('unselectAll');
            datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
        }
        function reset_(){
            $("#tableForm *").each(function(){
                $(":input:not(:checkbox,:radio)",this).val("");
            });
        }
         function modify_(){
            var rows = datagrid.datagrid("getSelections");
            if(!isChooseOne(rows)){return;}
            var href = '${path}/business/ipic_system/incoming/modifyUI.do?pid='+rows[0]['pid']+"&year="+rows[0]['year']+"&sid="+rows[0]['sid'];
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.modify'/>',
                width:820,height:500
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
        
          function add_() {
            var href = '${path}/business/ipic_system/incoming/addUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.create'/>',
                width:820,height:500
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
        
          function delete_(){
          
            var rows = datagrid.datagrid("getSelections");
            var effectData = new Object();
            effectData["incomingDetail"] = JSON.stringify(rows);
            
            $.messager.confirm(
                    '<spring:message code='msg'/>',
                    '<spring:message code='msg.confirm.delete'/>',
                    function(r){
                        if (r){
                            imonJYRH.showZone();
                            $.ajax({
                                url : imonJYRH.url("${path}/business/ipic_system/incoming/ajaxDelete.do"),
                                cache : false,
                                data : effectData,
                                dataType : "json",
                                success : function(reMsg) {
                                   if(reMsg.success){
                                        search_();
                                        message.show({
                                            msg : reMsg.msg,
                                            title : '<spring:message code='msg.tip'/>',
                                            showType:'slide'
                                        });
                                    }else{
                                        message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                                    }
                                    imonJYRH.hideZone();
                                }
                            });
                        }
                    });
        }
          /**
           *来料录入导入
           */
           function import_(){
               var href = '${path}/excel/incomingExcel/incomingImportUI.do';
               operateDialog = $("#operateDialog").dialog({
                   title : '<spring:message code='msg.import'/>',
                   width : 800,
                   height : 520
               });
               $("#operateIFrame")[0].src=href;
               operateDialog.dialog('open');
               imonJYRH.showZone();
           }
          //刷新当前页面，目的解决重新导入时不能选择文件
          function reloadFrame(){
        	  window.location = window.location.href;
          }
      function dialogSupplier_(){
            var href = '${path}/basedata/supplier/dialogUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.dialog.choose'/>',
                width : 650,
                height : 400
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
     function dialogSupplierReturn(row){
            $("#supplierId").val(row['id']);
            $("#supplierCode").val(row['code']);
            $("#supplierName").val(row['name']);
            operateDialog.dialog('close');
        }
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" style="overflow: hidden;">
    <div class="datagrid-toolbar" style="height:auto;">
        <br/>
        <fieldset>
           <table id="tableForm" width="100%">
                <tr>
                    <td align="right"><spring:message code="label.year"/>：</td>
                    <td>
                        <input type="text" name="year" value="${year}" id="year"
                               onFocus="WdatePicker({isShowClear:false,isShowToday:false,dateFmt:'yyyy',readOnly:true})" class="field Wdate"/>
                    </td>
                    <td align="right"><spring:message code="label.supplier.code"/>：</td>
                    <td>
                        <input type="hidden" id='supplierId' name="supplierId"/>
                        <input type="text" id="supplierCode" onclick="dialogSupplier_();" readonly="true"/>
                    </td>
                    <td align="right"><spring:message code='label.supplier.name'/>:</td>
                    <td align="left">
                        <input type="text" id="supplierName" style="width: 180px;" disabled/>
                    </td>
                </tr>
            </table>
        </fieldset>
        <br/>
    </div>
</div>
<div data-options="region:'center'">
    <div id="tb">
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-search" onclick="search_();"><spring:message code="bar.command.search"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message code="bar.command.reset"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-add" onclick="add_();"><spring:message code="bar.command.add"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="modify_();"><spring:message code="bar.command.modify"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message code="bar.command.delete"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-import" onclick="import_();"><spring:message code="bar.command.import"/></a>
    </div>
      <table id="datagrid" toolbar="#tb" pagination="true" fit="true" nowrap="false" singleSelect="true">
        <thead>
        <tr>
            <th field="ck" checkbox="true" rowspan="2"></th>
             <th field="pid" hidden="true"/>
             <th field="sid" hidden="true"/>
             <th field="supplierCode" width="100" align="center" rowspan="2">supplierCode<br/>供应商编码</th>
            <th field="supplierName" width="200" align="center" rowspan="2">SupplierName<br/>供应商名称</th>
            <th field="partNum" width="80" align="center" rowspan="2">PartNum<br/>零件号</th>
            <th field="partName" width="100" align="center" rowspan="2">PartName<br/>零件名称</th>
            <th field="year" width="80" align="center" rowspan="2">Year<br/>年份</th>
            <th colspan="12">PartCount零件数量</th>
           
        </tr>
        <tr>
            <th field="january" width="60" align="center">January<br/>一月</th>
            <th field="february" width="60" align="center">February<br/>二月</th>
            <th field="march" width="60" align="center">March<br/>三月</th>
            <th field="april" width="60" align="center">April<br/>四月</th>
            <th field="may" width="60" align="center">May<br/>五月</th>
            <th field="june" width="60" align="center">June<br/>六月</th>
            <th field="july" width="60" align="center">July<br/>七月</th>
            <th field="august" width="60" align="center">August<br/>八月</th>
            <th field="september" width="60" align="center">September<br/>九月</th>
            <th field="october" width="60" align="center">October<br/>十月</th>
            <th field="november" width="60" align="center">November<br/>十一月</th>
            <th field="december" width="60" align="center">December<br/>十二月</th>
        </tr>
        </thead>
    </table>
</div>
<div id="operateDialog" class="easyui-dialog"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>